<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core">

	<ui:composition>
		<h:form id="form-search">
			<table id="search-result" cellpadding="0" cellspacing="0">
				<tr>
					<td id="search-top-bar">
						<h:outputText value="#{msg['search.menu.header.pesquisar']}" />:<p:spacer width="5px" />
						<p:inputText id="searchTerm" styleClass="inputText" value="#{searchController.searchField}" />
						<p:watermark for="searchTerm" value="#{msg['search.menu.header.placeholder']}"/>
					</td>
					<td id="search-top-button">
						<p:commandButton value="#{msg['search.menu.button.buscar']}" ajax="false" actionListener="#{searchController.searchOpenFields}" image="search-button"/>
					</td>
					<td id="search-top-info">
						<h:outputFormat value="#{msg['search.menu.header.resultados']}">
							<f:param value="#{searchController.lazyModelAnuncio.rowCount}" />							
						</h:outputFormat>
					</td>
				</tr>
				<tr>
					<td id="search-result-panel" colspan="3">
						<p:outputPanel id="search-grid-panel">
							<p:dataTable 
								var="anuncio" 
								value="#{searchController.lazyModelAnuncio}" 
								lazy="true" 
								rows="#{searchController.pageSize}" 
								paginator="true"
								paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
								rowsPerPageTemplate="#{searchController.pageSize}"
								emptyMessage="#{msg['messages.list.not.found']}">
								
								<p:column style="padding: 2px;">
									<table cellpadding="0" cellspacing="0" border="1">
										<tr class="result-search-row">
											<td class="result-search-column-logo"><p:graphicImage value="#{anuncio.logo}" /></td>
											<td class="result-search-column-info" style="padding: 0px;">
												<table cellpadding="0" cellspacing="0">
													<tr class="result-search-row">
														<td class="result-search-column"><b><h:outputText value="#{anuncio.empresa.pessoaJuridica.nome}" /></b></td>
													</tr>
													<tr  class="result-search-row">
														<td class="result-search-column">
															<h:outputText value="#{anuncio.empresa.endereco.rua}"/>,<p:spacer width="2px" />
															<h:outputText value="#{anuncio.empresa.endereco.numero}"/>
														</td>
													</tr>
													<tr  class="result-search-row">
														<td class="result-search-column">															
															<h:outputText value="#{anuncio.empresa.endereco.bairro}"/>
														</td>
													</tr>
													<tr  class="result-search-row">
														<td class="result-search-column">															
															<h:outputText value="#{msg['manager.anuncio.create.endereco.edificio']}" />:<p:spacer width="2px" />
															<h:outputText value="#{anuncio.empresa.endereco.edificio}"/>
														</td>
													</tr>
													<tr class="result-search-row">
														<td class="result-search-column">
															<h:outputText value="#{anuncio.empresa.endereco.municipio.nome}"/><p:spacer width="2px" />
															<h:outputText value="#{msg['manager.anuncio.create.endereco.cep']}"/>:<p:spacer width="2px" /><h:outputText value="#{anuncio.empresa.endereco.cep}"/>
														</td>
													</tr>													
													<tr class="result-search-row">
														<td class="result-search-column">
															<h:outputText value="#{anuncio.descricao}"/>
														</td>
													</tr>
													<tr class="result-search-row">
														<td class="result-search-column">
															<h:outputText value="#{msg['search.result.compartilhe.label']}"/>:<p:spacer width="2px" />
														</td>
													</tr>
													<p:outputPanel rendered="#{anuncio.cliente.paginaPessoal}">
														<tr class="result-search-row">
															<td class="result-search-column">
																<h:commandLink action="#{templateController.loadTemplate}" target="_blank">
																	<h:outputText value="#{anuncio.cliente.pessoa.nome}" />
																	<f:param name="idCliente" value="#{anuncio.cliente.id}" />
																</h:commandLink>															
															</td>
														</tr>
													</p:outputPanel>													
													<tr class="result-search-row">
														<td class="result-search-column"><p:spacer height="10px"/></td>
													</tr>
													<tr class="result-search-row">
														<td class="result-search-column">	
															<p:commandLink value="#{msg['search.result.mapa.label']}" oncomplete="mapaDialog.show()" actionListener="#{searchController.loadAnuncioById}" update=":mapa-panel" >																
																<f:param name="idAnuncio" value="#{anuncio.id}" />
															</p:commandLink>
															<p:spacer width="2px" />|<p:spacer width="2px" />															
															<p:commandLink value="#{msg['search.result.telefone.label']}" oncomplete="telefonesDialog.show()" update=":telefone-panel" 
																actionListener="#{searchController.auditarClick}">
																<f:param name="idAnuncio" value="#{anuncio.id}" />
																<f:param name="tipo" value="T" />
															</p:commandLink>
															<p:spacer width="2px" />|<p:spacer width="2px" />															
															
															<p:commandLink value="#{msg['search.result.album.label']}" oncomplete="fotografiasDialog.show()" update=":fotografia-panel"
																actionListener="#{searchController.auditarClick}" rendered="#{!anuncio.albumIsEmpty}">
																<f:param name="idAnuncio" value="#{anuncio.id}" />
																<f:param name="tipo" value="F" />
															</p:commandLink>																														
															<h:outputText value="#{msg['search.result.album.label']}" rendered="#{anuncio.albumIsEmpty}" />
																												
															<p:spacer width="2px" />|<p:spacer width="2px" />
															<p:commandLink value="#{msg['search.result.email.label']}" oncomplete="contatoDialog.show()" update=":contato-panel" 
																actionListener="#{searchController.loadAnuncioById}">
																<f:param name="idAnuncio" value="#{anuncio.id}" />
															</p:commandLink>														
															<p:spacer width="2px" />|<p:spacer width="2px" />
															<p:commandLink value="#{msg['search.result.site.label']}" onclick="window.open('http://#{anuncio.empresa.site}')" 
																ajax="true" actionListener="#{searchController.auditarClick}" rendered="#{anuncio.empresa.site != ''}">																
																<f:param name="idAnuncio" value="#{anuncio.id}" />	
																<f:param name="tipo" value="S" />
															</p:commandLink>
															<h:outputText value="#{msg['search.result.site.label']}" rendered="#{anuncio.empresa.site == ''}" />																																												
														</td>
													</tr>
												</table>																					
											</td>
											<td class="result-search-column-reputation" style="padding: 0px;">
												<table cellpadding="0" cellspacing="0">
													<tr class="result-search-row">
														<td class="result-search-column" colspan="2">
															<b><h:outputText value="#{msg['search.result.reputacao.label']}"/></b>
														</td>
													</tr>
													<tr class="result-search-row">
														<td class="result-search-column-title">
															<h:outputText value="#{msg['search.result.atendimento.label']}"/>														
														</td>
														<td>
															<p:rating stars="5" value="#{anuncio.reputacaoAtendimento}" rateListener="#{searchController.loadSelectedAnuncio}" onRate="comentarioServicoDialog.show()">															
																<f:attribute name="idAnuncio" value="#{anuncio.id}" />
																<f:attribute name="tipo" value="A"/>
															</p:rating>											
														</td>
													</tr>
													<tr class="result-search-row">
														<td class="result-search-column-title">
															<h:outputText value="#{msg['search.result.servico.label']}"/>														
														</td>
														<td>
															<p:rating stars="5" value="#{anuncio.reputacaoServico}" rateListener="#{searchController.loadSelectedAnuncio}" onRate="comentarioServicoDialog.show()">															
																<f:attribute name="idAnuncio" value="#{anuncio.id}" />
																<f:attribute name="tipo" value="S"/>  
															</p:rating>	
														</td>
													</tr>
													<tr class="result-search-row">
														<td class="result-search-column" colspan="2">
															<b>
																<p:commandLink value="#{msg['search.result.comentarios.label']}" actionListener="#{searchController.loadAnuncioById}" 
																	oncomplete="comentariosDialog.show()" update=":comentarios-panel">
																	<f:param name="idAnuncio" value="#{anuncio.id}" />
																</p:commandLink>
															</b>
														</td>
													</tr>											
												</table>
											</td>
											<td class="result-search-column-map" style="padding: 0px;">
												<p:gmap center="#{anuncio.localizacao}" zoom="15" model="#{anuncio.mapModel}" type="terrain" 
													style="width:180px;height:120px" mapTypeControl="false" navigationControl="false" />  
											</td>
										</tr>
									</table>															
								</p:column>													
								
							</p:dataTable>
						</p:outputPanel>
					</td>
				</tr>
			</table>
		</h:form>
		<p:dialog header="#{msg['search.anuncio.reputacao.comentario.title']}" widgetVar="comentarioAtendimentoDialog" resizable="false"  
             	width="420" showEffect="clip" hideEffect="fold" position="top" modal="true" styleClass="dialog" onHide="clearFieldsFormAtendimento()"> 
        	
        	<p:outputPanel id="comentario-atendimento-panel">
        		<h:form id="form-atendimento">
		           	<table cellpadding="0" cellspacing="0">
		           		<tr>
		           			<td class="form-column-label"><h:outputText value="#{msg['search.anuncio.comentario.nome']}" />:</td>
		           			<td class="form-column-value">
		           				<p:inputText id="nomeAtendimento" value="#{searchController.avaliacao.nome}" styleClass="inputText" />
		           			</td>
		           		</tr>
		           		<tr>
		           			<td class="form-column-label"><h:outputText value="#{msg['search.anuncio.comentario.email']}" />:</td>
		           			<td class="form-column-value">
		           				<p:inputText id="emailAtendimento" value="#{searchController.avaliacao.email}" styleClass="inputText" />	
		           			</td>
		           		</tr>
		           		<tr>
		           			<td class="form-column-label"><h:outputText value="#{msg['search.anuncio.comentario.descricao']}" />:</td>
		           			<td class="form-column-value">
		           				<p:inputTextarea id="descricaoAtendimento" value="#{searchController.avaliacao.descricao}" styleClass="inputTextArea" maxHeight="120" maxlength="255"/>
		           			</td>
		           		</tr>
		           		<tr>
		           			<td class="form-column-buttons" colspan="2">
		           				<p:commandButton value="#{msg['search.anuncio.comentario.send']}" actionListener="#{searchController.handleRate}" 
		           					 ajax="true" oncomplete="comentarioAtendimentoDialog.hide()" update=":form-search:search-grid-panel" image="send-button"/>
		           			</td>
		           		</tr>
		           	</table>
	          	</h:form>
           </p:outputPanel>              			              
        </p:dialog>
        
        <p:dialog header="#{msg['search.anuncio.reputacao.comentario.title']}" widgetVar="comentarioServicoDialog" resizable="false"  
             	width="420" showEffect="clip" hideEffect="fold" position="top" modal="true" styleClass="dialog" onHide="clearFieldsFormServico()"> 
             	
        	<p:outputPanel id="comentario-servico-panel">
        		<h:form id="form-servico">
		           	<table cellpadding="0" cellspacing="0">
		           		<tr>
		           			<td class="form-column-label"><h:outputText value="#{msg['search.anuncio.comentario.nome']}" />:</td>
		           			<td class="form-column-value">
		           				<p:inputText id="nomeServico" value="#{searchController.avaliacao.nome}" styleClass="inputText" />
		           			</td>
		           		</tr>
		           		<tr>
		           			<td class="form-column-label"><h:outputText value="#{msg['search.anuncio.comentario.email']}" />:</td>
		           			<td class="form-column-value">
		           				<p:inputText id="emailServico" value="#{searchController.avaliacao.email}" styleClass="inputText" />	
		           			</td>
		           		</tr>
		           		<tr>
		           			<td class="form-column-label"><h:outputText value="#{msg['search.anuncio.comentario.descricao']}" />:</td>
		           			<td class="form-column-value">
		           				<p:inputTextarea id="descricaoServico" value="#{searchController.avaliacao.descricao}" styleClass="inputTextArea" maxHeight="120" maxlength="255"/>
		           			</td>
		           		</tr>
		           		<tr>
		           			<td class="form-column-buttons" colspan="2">
		           				<p:commandButton value="#{msg['search.anuncio.comentario.send']}" actionListener="#{searchController.handleRate}" 
		           					 ajax="true" oncomplete="comentarioServicoDialog.hide()" update=":form-search:search-grid-panel" image="send-button"/>
		           			</td>
		           		</tr>
		           	</table>
	          	</h:form>
           </p:outputPanel> 	             
        </p:dialog>	
        
        <p:dialog header="#{msg['search.anuncio.contato.title']}" widgetVar="contatoDialog" resizable="false"  
             	width="420" showEffect="clip" hideEffect="fold" position="top" modal="true" styleClass="dialog" onHide="clearFieldsFormContato()"> 
             	
        	<p:outputPanel id="contato-panel">
        		<h:form id="form-contato">
		           	<table cellpadding="0" cellspacing="0">
		           		<tr>
		           			<td class="form-column-label"><h:outputText value="#{msg['search.anuncio.contato.nome']}" />:</td>
		           			<td class="form-column-value">
		           				<p:inputText id="nomeMensagem" value="#{searchController.mensagem.nome}" styleClass="inputText" />
		           			</td>
		           		</tr>
		           		<tr>
		           			<td class="form-column-label"><h:outputText value="#{msg['search.anuncio.contato.email']}" />:</td>
		           			<td class="form-column-value">
		           				<p:inputText id="emailMensagem" value="#{searchController.mensagem.email}" styleClass="inputText" />	
		           			</td>
		           		</tr>
		           		<tr>
		           			<td class="form-column-label"><h:outputText value="#{msg['search.anuncio.contato.descricao']}" />:</td>
		           			<td class="form-column-value">
		           				<p:inputTextarea id="descricaoMensagem" value="#{searchController.mensagem.descricao}" styleClass="inputTextArea" maxHeight="120" maxlength="255"/>
		           			</td>
		           		</tr>
		           		<tr>
		           			<td class="form-column-buttons" colspan="2">
		           				<p:commandButton value="#{msg['search.anuncio.contato.send']}" ajax="true" oncomplete="contatoDialog.hide()"
		           					update=":form-search:search-grid-panel" image="send-button" actionListener="#{searchController.sendMessage}"/>
		           			</td>
		           		</tr>
		           	</table>
	          	</h:form>
           </p:outputPanel> 	             
        </p:dialog>			
        
        <p:dialog header="#{msg['search.anuncio.reputacao.comentarios.title']}" widgetVar="comentariosDialog" resizable="false"  
             	width="620" showEffect="clip" hideEffect="fold" position="top" modal="true" styleClass="dialog">
        	<p:outputPanel id="comentarios-panel">
        		<h:form>
        			<p:dataTable 
        				var="avaliacao" 
        				value="#{searchController.anuncio.avaliacoes}" 
        				scrollable="true" 
        				scrollHeight="200"
        				resizableColumns="true"
        				emptyMessage="#{msg['messages.list.not.found']}">
        				        			
        				<p:column styleClass="search-comentarios-column-tipo" headerText="#{msg['search.anuncio.comentario.tipo']}">        					
	        				<h:outputText value="#{msg['search.anuncio.comentario.tipo.atendimento']}" rendered="#{avaliacao.tipoAvaliacao == 'ATENDIMENTO'}"/>
	        				<h:outputText value="#{msg['search.anuncio.comentario.tipo.servico']}" rendered="#{avaliacao.tipoAvaliacao == 'SERVICO'}"/>
	        			</p:column>
	        			<p:column styleClass="search-comentarios-column-nome" headerText="#{msg['search.anuncio.comentario.nome']}">
	        				<h:outputText value="#{avaliacao.nome}" />
	        			</p:column>
	        			<p:column styleClass="search-comentarios-column-nota" headerText="#{msg['search.anuncio.comentario.rate']}">
	        				<h:outputText value="#{avaliacao.descClassificacao}" />
	        			</p:column>
	        			<p:column styleClass="search-comentarios-column-descricao" headerText="#{msg['search.anuncio.comentario.descricao']}">
	        				<h:outputText value="#{avaliacao.descricao}" />
	        			</p:column>
        			</p:dataTable>
        		</h:form>        		        		
        	</p:outputPanel>
        </p:dialog>
        
        <p:dialog header="#{msg['search.result.album.label']}" widgetVar="fotografiasDialog" resizable="false" 
        	modal="true" styleClass="dialog" showEffect="clip" position="top" width="520">        	
        	<p:outputPanel id="fotografia-panel">
        		<p:galleria>
        			<ui:repeat var="photo" value="#{searchController.anuncio.album}">
        				<p:graphicImage value="#{photo.originalImage}" title="#{photo.legenda}" alt="#{photo.legenda}" />
        			</ui:repeat>
        		</p:galleria>
        	</p:outputPanel>         	
        </p:dialog>
        
        <p:dialog header="#{msg['search.result.telefone.label']}" widgetVar="telefonesDialog" resizable="false" 
        	modal="true" styleClass="dialog" showEffect="clip" position="top" width="220" height="120">
        	<p:outputPanel id="telefone-panel">
       		 	<table cellpadding="0" cellspacing="0">
	           		<tr>
	           			<td class="form-column-label"><h:outputText value="#{msg['manager.cliente.create.telefone.fixo']}" />:</td>
	           			<td class="form-column-value">
	           				<h:outputText value="#{searchController.anuncio.empresa.telefoneFixo}" />
	           			</td>
	           		</tr>
	           		<tr>
	           			<td class="form-column-label"><h:outputText value="#{msg['manager.cliente.create.telefone.celular']}" />:</td>
	           			<td class="form-column-value">
	           				<h:outputText value="#{searchController.anuncio.empresa.telefoneCelular}" />
	           			</td>
	           		</tr>
	           	</table>
        	</p:outputPanel>
        </p:dialog>
        
        <p:dialog header="#{msg['search.result.mapa.label']}" widgetVar="mapaDialog" resizable="false" modal="true" position="top" width="500" showEffect="clip" onShow="reloadMapa()"> 
        	<p:outputPanel id="mapa-panel">
        		<p:gmap widgetVar="zoomMap" center="#{searchController.anuncio.localizacao}" model="#{searchController.anuncio.mapModel}" zoom="15" type="terrain" 
       				style="width:480px;height:300px" mapTypeControl="false" navigationControl="false" />
        	</p:outputPanel>       	       	       	  
        </p:dialog>
                	
	</ui:composition>
</html>